
  <script type="text/javascript" src="__PUBLIC__/js/zTree_v3/js/jquery.ztree.all-3.5.min.js"></script>
 <link rel="stylesheet" href="__PUBLIC__/js/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<div class="card">
	<div class="card-content">
		<div class = 'row row-head' >
			<div class = 'col s12' >
				<div class="btn-group left  margin-right-100" role="group" >
					<button class = 'btn btn-default btn-default-1' id = 'add'>  <i class="material-icons text-color2"  >add_box</i> 新增</button>
		
					<button class = 'btn btn-default btn-default-1' id = 'dlt'>  <i class="material-icons text-color3"  >clear</i> 删除</button>
			
			
				</div>
				
			</div>
		</div>

		<div class = 'row row-body'>
			
		
			
			<div class = 'col s7' style = 'border-right:1px solid #cfcfcf'>
				<div class = 'relative left'>
						<input type = 'text' id = 'search_table' class = 'width-200' placeholder = '按回车搜索' />
						<img src = '__PUBLIC__/image/search.png' class = 'absolute height18 input-hint' />
					</div>
					<table class = 'dataTable centered  row-border stripe' id = 'table'>
						<thead>
							<tr><th>岗位名称</th><th>岗位类型</th><th>排序</th><th>状态</th></tr>
						</thead>
						<tbody>
						{volist name = 'list' id = 'p'}
						<tr data-id = '{$p.id}'><td>{$p.name}</td><td>{$p.type_name}</td><td>{$p.sort}</td><td>{$p.status?'启用':'禁用'}</td></tr>
						{/volist}
						</tbody>
					</table>
			</div>

				<div class = 'col s5' >
				<div class = 'row new-container' >
					
					<div class = 'col s4'>岗位名称</div><div class = 'col s8'><input id = 'name' class = 'aya-input' type = 'text' /></div>
					<div class = 'col s4'>岗位类型</div><div class = 'col s8'>
						<select class = 'browser-default' id = 'type_id'>
						{volist name = 'post_type' id = 'p'}
						<option value = '{$p.id}'>{$p.name}</option>
						{/volist}
						</select>
					</div>
					
					
					<div class = 'col s4'>排序</div><div class = 'col s8'><input id = 'sort' class = 'aya-input' type = 'text' /></div>
					
					<div class = 'col s4'>状态</div><div class = 'col s8'>
						<select id = 'status' class = 'browser-default'>
							<option value = '1'>启用</option>
							<option value = '0'>禁用</option>
						</select>
					</div>
					
					<div class = 'col s12' style = 'text-align:center'><button class = 'btn btn-primary height32' id = 'save'>保 存</button></div>
					<input type = 'hidden' id = 'pid' />
				</div>
			</div>
		</div>
		


		
					
	</div>
</div>


<script>
	var app = {
		
		field : ['pid','name','level','sort'],

		zTreeObj : {},

		node : null,

		maxSort : {$sortmax},
		
		ini : function(){
			
			let table = d_table();

			$('#search_table').keypress(function(e){
				let text = $.trim($(this).val());
				if(e.keyCode == 13){
					table.search(text).draw();
				}
			});


			$('#table').on('click','tr',function(){
				$('#name').val($(this).children().eq(0).text());

				$('#sort').val($(this).children().eq(2).text());

				let status = $(this).children().eq(3).text();
				let type   = $(this).children().eq(1).text();

				$('#status option').each(function(){
					if($(this).text() == status){
						$('#status').val($(this).attr('value'));
					}
				});

				$('#type_id option').each(function(){
					if($(this).text() == type){
						$('#type_id').val($(this).attr('value'));
					}
				});
			});

			

			$('#save').click(function(){

				if($('#table tbody tr.selected').length == 0) return false;

				let o = {};
				o.id = $('#table tbody tr.selected').eq(0).data('id');
				o.name = $.trim($('#name').val());
				o.sort = $.trim($('#sort').val());
				o.type_id = $.trim($('#type_id').val());
				o.status = $.trim($('#status').val());
				
				
			
				$.post('__APP__/Pst/editPst',o,function(d){
					
					if(d.status == 's'){
						let tmp = $('#table tbody tr.selected').eq(0).children();

						tmp.eq(0).text(d.data.name);
						tmp.eq(1).text(d.data.type_name);
						tmp.eq(2).text(d.data.sort);
						tmp.eq(3).text(d.data.status == 1?'启用':'禁用');
						
						layer_success()

					}else{

						layer_error(d);

					}
				});
			});
			
			

			
			
		
			$('#dlt').click(function(){

				
				if($('#table tr.selected').length == 0 ) return false;

				

				parent.layer.confirm('确定删除?', { icon: 3, title:'提示',offset : ['10%' ] }, function(index){

					let o = {};

					o.name = $('#table tr.selected').eq(0).children().eq(0).text();

					

					$.post('__APP__/Pst/dltPst',o,function(d){

						if(d.status == 's'){
							$('#table tr.selected').remove();
							
							layer_success();

						}else{

							layer_error(d);

						}

					});
				});

			});
			
			

			$('#add').click(function(){
				let div = [
					{ 'name' : '岗位名称：' ,'id' : 'name_new' ,'type' : 'text'},
					{ 'name' : '岗位类型：' ,'id' : 'type_id_new' ,'type' : 'select','data' : {$post_type|raw} },
					{ 'name' : '排序：' ,'id' : 'sort_new' ,'type' : 'text'},
				
				];

				top.layer.open({

					skin: 'layer-edit-container',

					title : '编辑节点',

					offset : ['40px'],

					area  : ['600px',"300px"],

					type  : 1,

					btn   : ['确定'],

					shadeClose:true,

					content : create_new_div( div ),

					success : function(){
						$('#sort_new').val( app.maxSort + 1);
					},

					yes : function(index){

						let o = {};

						for(let f of div){
							o[f.id] = $.trim(top.$('#' + f.id).val());
						}

						$.post('__APP__/Pst/addPst',o,function(d){
							if(d.status == 's'){
								
								table.rows.add($(d.data)).draw();
								app.maxSort = d.info;
								top.layer.close(index);
							
								layer_success();
							}else{
								layer_error(d);
							}
						});
					}
				});

			});


		},	



	}
	app.ini();
</script>



